package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.production.ComProductionDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.production.ComProductionVO;
import com.bf.electroplating.service.ComProductionService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/production")
@Tag(name = "电镀生产信息", description = "电镀生产信息管理")
public class ComProductionController {

    @Autowired
    private ComProductionService comProductionService;

    @PostMapping("/list")
    @Operation(summary = "获取生产信息列表", description = "分页获取电镀生产信息列表")
    public ResultVO<Page<ComProductionVO>> getProductionList(@RequestBody ComProductionDTO dto) {
        return ResultVO.ok(comProductionService.getProductionList(dto));
    }

    @PostMapping("/getProductionById")
    @Operation(summary = "获取生产信息详情", description = "根据ID获取电镀生产信息详情")
    public ResultVO<ComProductionVO> getProductionById(@RequestBody IdDTO id) {
        return ResultVO.ok(comProductionService.getProductionById(id.getId()));
    }

    @Idempotent
    @PostMapping("/saveProduction")
    @Operation(summary = "新增生产信息", description = "新增电镀生产信息")
    public ResultVO<Boolean> saveProduction(@RequestBody ComProductionVO vo) {
        return ResultVO.ok(comProductionService.saveProduction(vo), "保存成功");
    }

    @Idempotent
    @PostMapping("/updateProduction")
    @Operation(summary = "修改生产信息", description = "修改电镀生产信息")
    public ResultVO<Boolean> updateProduction(@RequestBody ComProductionVO vo) {
        return ResultVO.ok(comProductionService.updateProduction(vo), "保存成功");
    }

    @PostMapping("/deleteProduction")
    @Operation(summary = "删除生产信息", description = "根据ID删除电镀生产信息")
    public ResultVO<Boolean> deleteProduction(@RequestBody IdDTO id) {
        return ResultVO.ok(comProductionService.deleteProduction(id.getId()), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除生产信息", description = "批量删除电镀生产信息")
    public ResultVO<Boolean> batchDeleteProduction(@RequestBody List<String> ids) {
        return ResultVO.ok(comProductionService.batchDeleteProduction(ids), "删除成功");
    }
} 